<template>
    <el-dialog :visible.sync="visible" title="删除人员信息" @close="closeDialog">
      <el-form :model="form" ref="form" label-width="120px" :rules="rules">
        <el-form-item label="账号" prop="account">
          <el-input v-model="form.account" @blur="search"></el-input>
        </el-form-item>
        <el-form-item label="名称" >
          <el-input v-model="form.name" disabled></el-input>
        </el-form-item>
        <el-form-item label="邮箱" >
          <el-input v-model="form.email" disabled></el-input>
        </el-form-item>
        <el-form-item label="手机号" >
          <el-input v-model="form.phone" disabled></el-input>
        </el-form-item>
        <el-form-item label="地区id" >
          <el-input v-model="form.region_id" disabled></el-input>
        </el-form-item>
        <el-form-item label="职称" >
          <el-input v-model="form.position" disabled></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="closeDialog">取消</el-button>
        <el-button type="danger" @click="onSubmit">删除</el-button>
      </span>
    </el-dialog>
  </template>
  
  <script>
  import axios from 'axios';
  export default {
    name: 'DeletePersonDialog',
    props: {
      visible: {
        type: Boolean,
        default: false
      }
    },
    data() {
      return {
        form: {
          account: '',
          name:'',
          region_id:'',
          position:'',
          phone:'',
          email:''
        },
        rules: {
          account: [
            { required: true, message: '请输入账号', trigger: 'blur' }
          ]
        }
      };
    },
    methods: {
      search(){
        axios.post('/api/person/searchOne',this.form.account, {
            headers: {
              'Content-Type': 'text/plain'
            }
          })
        .then(res=>{
          console.log(res.data)
          this.form.name=res.data.name;
          this.form.phone = res.data.phone;
          this.form.email = res.data.email;
          this.form.region_id = res.data.region_id;
          this.form.position = res.data.position;
        })
      },
      closeDialog() {
        this.$emit('close');
      },
      onSubmit() {
        axios.post('/api/person/delete',this.form.account, {
            headers: {
              'Content-Type': 'text/plain'
            }
          }).then(res=>{
            this.$message.success('删除成功')
          this.$emit('close');
          }).catch(error=>{
            this.$message.error('删除失败')
          })
        
      },
      
    }
  };
  </script>
  
  <style scoped>
  /* 样式 */
  </style>
  